package com.singfan.app;

import com.pingplusplus.model.Charge;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.singfan.app.controller.AdminController;
import com.singfan.app.controller.model.RequestModelBase;
import com.singfan.app.controller.model.request.*;
import com.singfan.common.util.CheckUtil;
import com.singfan.common.util.HttpClientUtil;
import com.singfan.common.util.JsonUtil;
import com.singfan.common.util.TimeUtil;
import com.singfan.core.dao.database.model.Orders;
import com.singfan.core.dao.database.model.constant.PayChannelType;
import com.singfan.core.dao.database.model.constant.PlatformType;
import com.singfan.core.util.PayUtil;
import com.singfan.core.util.PushUtil;
import com.singfan.core.util.SmsUtil;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;

/**
 * Author: HanSongHe
 * Date: 2015-09-04 19:57
 * Desc:
 */
public class Test {
//    private static final String host = "http://api.singfan.cn";
    private static final String host = "http://192.168.0.200:8080";
    private static final String customerToken = "188292646190587904-1-48b31208";
    public static void main(String[] args){
        //SmsUtil.sendSecurityCode("15801683312","9527");
        //barberListRequest();
        //hairStyleRecommendRequest();
        //shopDetailRequest();
        //collectList();
//        PushUtil.push("011cc27bc2b", 1, PlatformType.IOS, "给沈健客户端发送的推送");
//        barberAppointment();
//        provideCoupon();
//        shopListRequest();
//        payTest();

//        uploadTest();
//        barberMyIncomeTotal();

//        myWorks();
//        orderFinish();
        boolean result = CheckUtil.isPositiveInteger("9");
        System.out.println(result);
    }


    private static void uploadTest() {
        try {
            UploadManager uploadManager = new UploadManager();
            Auth auth = Auth.create("dpLrsXOAeQtki8qdgpC8ZiaDL3W3H3ZRLU2vkaV1", "zXsG2to1cP1gnlkUllJ6MP9965d1ecegGKZSm8sr");
            String uploadToken = auth.uploadToken("singfan-picture");
            Response res = uploadManager.put("shengjianshangcuan".getBytes(), UUID.randomUUID().toString(), uploadToken);
            System.out.println(res);
        } catch (QiniuException e) {
            Response r = e.response;
            // 请求失败时简单状态信息
            System.out.println(r.toString());
            try {
                // 响应的文本信息
                System.out.println(r.bodyString());
            } catch (QiniuException e1) {
                //ignore
            }
        }
    }

    private static void myWorks(){
        BarberMyWorksRequest barberMyWorksRequest = new BarberMyWorksRequest();
        barberMyWorksRequest.setAccessToken("10000108-2-fb558deb");
        barberMyWorksRequest.setPageIndex(0);
        barberMyWorksRequest.setPageSize(20);
        barberMyWorksRequest.setStatus(1);

        post("/v1/barber/myworks", barberMyWorksRequest);
    }

    private static void orderFinish(){
        OrderBarberFinishRequest orderBarberFinishRequest = new OrderBarberFinishRequest();
        orderBarberFinishRequest.setAccessToken("10000108-2-fb558deb");
        orderBarberFinishRequest.setOrderId(200725863548198912L);

        post("/v1/barber/order/finish", orderBarberFinishRequest);
    }

    private static void barberMyIncomeTotal(){
        BarberMyIncomeTotalRequest barberMyIncomeTotalRequest = new BarberMyIncomeTotalRequest();
        barberMyIncomeTotalRequest.setAccessToken("10000108-2-4ad16150");

        post("/v1/barber/myincome/total", barberMyIncomeTotalRequest);
    }

    private static void payTest(){
        long orderId = 1234567801;
        Charge charge = PayUtil.charge(100, "order-" + 123, "" + 1 + "-" + 2 + "-" + 100, String.valueOf(orderId), PayChannelType.PAY_UNION, "114.249.20.225");
        System.out.println(charge);
    }

    private static void provideCoupon(){
        long now = System.currentTimeMillis();
        long oneDayTime = 24 * 60 * 60 * 1000;
        CouponProvide couponProvide = new CouponProvide();
        couponProvide.setShopId(0);
        couponProvide.setAmount(200000);
        couponProvide.setPriceCondition(0);
        couponProvide.setExpiredTime(now + 10*oneDayTime);

        post("/v1/admin/coupon/provide", couponProvide);
    }

    private static void barberAppointment(){
        BarberAppointmentRequest barberAppointmentRequest = new BarberAppointmentRequest();
        barberAppointmentRequest.setAccessToken("191303504164429824-1-f2b07de7");
        barberAppointmentRequest.setDayTime(20150918);
        barberAppointmentRequest.setBarberId(10000130);

        post("/v1/barber/appointment", barberAppointmentRequest);
    }

    private static void collectList(){
        CustomerCollectListRequest customerCollectListRequest = new CustomerCollectListRequest();

        customerCollectListRequest.setAccessToken(customerToken);
        customerCollectListRequest.setItemType(1);
        customerCollectListRequest.setPageIndex(0);
        customerCollectListRequest.setPageSize(20);
        customerCollectListRequest.setLongitude("116.262800");
        customerCollectListRequest.setLatitude("39.956740");

        post("/v1/customer/collect/list", customerCollectListRequest);
    }

    private static void shopDetailRequest(){
        //shopId:80023, serviceType:1, longitude:116.301547, latitude:40.014348
        ShopDetailRequest shopDetailRequest = new ShopDetailRequest();
        //shopDetailRequest.setAccessToken(customerToken);
        shopDetailRequest.setShopId(80023);
        shopDetailRequest.setServiceType(1);
        shopDetailRequest.setLongitude("116.301547");
        shopDetailRequest.setLatitude("40.014341");

        post("/v1/shop/detail", shopDetailRequest);
    }

    private static void shopListRequest(){
//        resultCode:0, ip:121.79.145.100, accessToken:191463689264701440-1-2e93bae4, serviceType:7, listOrderType:0, cityId:10, businessCircleId:1, pageIndex:0, pageSize:10, dayTime:20150916, clockTime:1130, longitude:116.262787, latitude:39.956752
        ShopListRequest shopListRequest = new ShopListRequest();
        shopListRequest.setAccessToken("191463689264701440-1-2e93bae4");
        shopListRequest.setServiceType(7);
        shopListRequest.setListOrderType(0);
        shopListRequest.setCityId(10);
        shopListRequest.setBusinessCircleId(1);
        shopListRequest.setPageIndex(0);
        shopListRequest.setPageSize(10);
        shopListRequest.setDayTime(20150916);
        shopListRequest.setClockTime(1130);
        shopListRequest.setLongitude("116.262812");
        shopListRequest.setLatitude("39.956738");

        post("/v1/shop/list", shopListRequest);
    }

    private static void barberListRequest(){
        BarberListRequest barberListRequest = new BarberListRequest();
        barberListRequest.setAccessToken(customerToken);
        barberListRequest.setServiceType(0);
        barberListRequest.setListOrderType(1);
        barberListRequest.setCityId(10);
        barberListRequest.setBusinessCircleId(0);
        barberListRequest.setPageIndex(0);
        barberListRequest.setPageSize(20);
        barberListRequest.setOnlyMaster(false);
        barberListRequest.setLongitude("116.262812");
        barberListRequest.setLatitude("39.956747");

        post("/v1/barber/list", barberListRequest);
    }

    private static void hairStyleRecommendRequest(){
        HairStyleRecommendRequest hairStyleRecommendRequest = new HairStyleRecommendRequest();
        hairStyleRecommendRequest.setAccessToken(customerToken);
        hairStyleRecommendRequest.setListOrderType(2);
        hairStyleRecommendRequest.setCityId(10);
        hairStyleRecommendRequest.setBusinessCircleId(1);
        hairStyleRecommendRequest.setPageIndex(0);
        hairStyleRecommendRequest.setPageSize(20);
        hairStyleRecommendRequest.setLongitude("116.301635");
        hairStyleRecommendRequest.setLatitude("40.014341");
        hairStyleRecommendRequest.setGender(2);

        post("/v1/hairstyle/recommend/list", hairStyleRecommendRequest);
    }

    private static void post(String url, RequestModelBase requestModelBase){
        try {
            String result = HttpClientUtil.post(host + url, JsonUtil.bean2Json(requestModelBase), false);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
